package hu.mapro.rollerx.core;

import hu.mapro.rollerx.core.FractalTerrain.Vertices;

import org.j3d.texture.procedural.PerlinNoiseGenerator;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

public class Ground5 extends AbstractGround {

	private static final float START = 0;
	private static final float END = 150;
	private static final int WAVES = 6;
	private static final float AMPLITUDE = 30;
	private static final int STEPS = 100;
	
	private static final float WIDTH = END-START;
	
	public Ground5() {
		super(false);
	}
	
	@Override
	public Vector2 getCarPosition(float carWidth, float carHeight) {
		return new Vector2(-carWidth, 0);
	}

	float getPlatformWidth(float carWidth) {
		return carWidth*2;
	}
	
	@Override
	Vector2[][] generateVertices(float carWidth, float carHeight) {
		PerlinNoiseGenerator perlinNoiseGenerator = new PerlinNoiseGenerator(MathUtils.random.nextInt());
	
		Vertices vertices = new Vertices(STEPS+1+2);
		vertices.addVertex(START-carWidth*2, 0);
		
		for (int i=0;i<=STEPS;i++) {
			float x = (float)i/STEPS;
			float noise1 = perlinNoiseGenerator.noise1(x*WAVES);
			vertices.addVertex(START+(x*WIDTH), noise1*AMPLITUDE);
		}
		
		vertices.terrainVertices[1] = vertices.terrainVertices[3];
		
		vertices.addVertex(END+getPlatformWidth(carWidth), vertices.terrainVertices[vertices.terrainVerticeIdx-1]);
		
		return new Vector2[][] {
				vertices.toVector2Array()
		};
	}

}
